package com.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.entity.PageBean;
import com.mall.entity.R;
import com.mall.entity.WxUserInfo;
import com.mall.service.IWxUserInfoService;
import com.mall.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    private IWxUserInfoService wxUserInfoService;

    @RequestMapping("/list")
    public R list(@RequestBody PageBean pageBean) {
        String query = pageBean.getQuery().trim();
        Page<WxUserInfo> page = new Page<>(pageBean.getPageNum(), pageBean.getPageSize());
        Page<WxUserInfo> pageResult = wxUserInfoService.page(page, new LambdaQueryWrapper<WxUserInfo>()
                .like(StringUtil.isNotEmpty(query), WxUserInfo::getNickName, query));
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("userList", pageResult.getRecords());
        resultMap.put("total", pageResult.getTotal());
        return R.ok(resultMap);
    }
}
